import pandas as pd
import numpy as np


def fit_category_var(data: pd.DataFrame, target_column):
    observed_data = data.dropna(axis='index', how='any', subset=[target_column])
    result = []
    column = observed_data[target_column]
    value_range = column.unique()
    for i in value_range:
        # each category's frequency
        result.append(list(column).count(i)/len(column))
    np.random.seed(0)
    p = np.array(result)
    for index, value in enumerate(data[target_column]):
        if pd.isna(value):
            data.loc[index, target_column] = np.random.choice(value_range, p=p.ravel())


def fill_cnt_var(data: pd.DataFrame, target_column):
    data = data[target_column].fillna(0)
